package com.ruoyi.system.service.impl.King;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.KingTemporary.*;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.mapper.King.KingCangMapper;
import com.ruoyi.system.service.IKingBdCangService;
import com.ruoyi.system.service.IKingBdCangwService;
import com.ruoyi.system.service.IKingBdOrganizationService;
import com.ruoyi.system.service.IKingBdWuService;
import com.ruoyi.system.service.King.IKingCanService;
import com.ruoyi.system.util.InvokeHelper;
import com.ruoyi.system.util.ResultUtil;
import org.json.JSONArray;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;

/**
 * 参数配置 服务层实现
 * 
 * @author ruoyi
 */
@Service

public class KingCanServiceImpl implements IKingCanService
{
    @Autowired
    private KingCangMapper kingCangMapper;

    @Autowired
    private KingBdCangMapper kingBdCangMapper;

    @Autowired
    private KingBdCangwMapper kingBdCangwMapper;

    @Autowired
    private KingBdWuMapper kingBdWuMapper;

    @Autowired
    private KingBdOrganizationMapper kingBdOrganizationMapper;

    @Autowired
    private KingTableNameMapper kingTableNameMapper;

    @Autowired
    private IKingBdCangService iKingBdCangService;

    @Autowired
    private IKingBdCangwService iKingBdCangwService;

    @Autowired
    private IKingBdWuService iKingBdWuService;


    @Autowired
    private IKingBdOrganizationService iKingBdOrganizationService;

    @Autowired
    private KingAppVersionMapper kingAppVersionMapper;

    @Autowired
    private RedisCache redisCache;



    @Override
    public List<String> getAllCang() {
        List<String> list = kingCangMapper.getAllCang();
        return list;
    }

    @Override
    public List<String> getAllUser() {
        List<String> list = kingCangMapper.getAllUser();
        return list;
    }

    @Override
    public List<KingWu> getAllWu() {
        List<KingWu> list = kingCangMapper.getAllWu();
        return list;
    }

    @Override
    public List<String> getAllUnit() {
        List<String> list = kingCangMapper.getAllUnit();
        return list;
    }

    @Override
    public List<Map<String, String>> getAllStaff() {
        List<Map<String, String>> list = kingCangMapper.getAllStaff();
        return list;
    }

    @Override
    public List<StkMisc> userIdToStkmiscList(String userId){
        List<StkMisc> list = kingCangMapper.userIdToStkmiscList(userId);
        return list;
    }

    @Override
    public List<StkMiscKids> idToStkmisChildList(String fId){
        List<StkMiscKids> list = kingCangMapper.idToStkmisChildList(fId);
        if(list.size()>0){
            for(StkMiscKids stkMiscKids: list){
                if(StringUtils.isNotEmpty(kingBdWuMapper.fIdtoName(stkMiscKids.getfId()))){
                    stkMiscKids.setfName(kingBdWuMapper.fIdtoName(stkMiscKids.getfId()));
                }
                if(StringUtils.isNotEmpty(kingBdCangMapper.fIdtoName(stkMiscKids.getfCangId()))){
                    stkMiscKids.setfCangName(kingBdCangMapper.fIdtoName(stkMiscKids.getfCangId()));
                }
                if(StringUtils.isNotEmpty(kingBdCangwMapper.fIdtoName(stkMiscKids.getfWeiId()))){
                    stkMiscKids.setfWeiName(kingBdCangwMapper.fIdtoName(stkMiscKids.getfWeiId()));
                }
            }
        }
        return list;
    }

    @Override
    public List<StkMiscKids> idToStkmisChuChildList(String fId){
        List<StkMiscKids> list = kingCangMapper.idToStkmisChuChildList(fId);
        if(list.size()>0){
            for(StkMiscKids stkMiscKids: list){
                if(StringUtils.isNotEmpty(kingBdWuMapper.fIdtoName(stkMiscKids.getfId()))){
                    stkMiscKids.setfName(kingBdWuMapper.fIdtoName(stkMiscKids.getfId()));
                }
                if(StringUtils.isNotEmpty(kingBdCangMapper.fIdtoName(stkMiscKids.getfCangId()))){
                    stkMiscKids.setfCangName(kingBdCangMapper.fIdtoName(stkMiscKids.getfCangId()));
                }
                if(StringUtils.isNotEmpty(kingBdCangwMapper.fIdtoName(stkMiscKids.getfWeiId()))){
                    stkMiscKids.setfWeiName(kingBdCangwMapper.fIdtoName(stkMiscKids.getfWeiId()));
                }
            }
        }
        return list;
    }

    @Override
    public List<KingZjRk> getUserStk(List<StkMisc> list) throws Exception {
        List<KingZjRk> list1 = new ArrayList<>();
        if(list.size()>0){
            for(StkMisc stkMisc:list){
                KingZjRk kingZjRk = new KingZjRk();
                BeanUtils.copyProperties(stkMisc,kingZjRk);
                Ruku ruku = getRuku(stkMisc.getfId());
                kingZjRk.setfLei(ruku.getResult().getResult().getF_YMJT_Base1().getName().get(0).getValue());
                kingZjRk.setfWuliao(idToStkmisChildList(stkMisc.getfId()));
                list1.add(kingZjRk);
            }
        }
        return list1;
    }

    public static Ruku getRuku(String ids) throws Exception {
        Ruku ruku = new Ruku();
        if(org.apache.commons.lang3.StringUtils.isNotEmpty(ids)){
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("CreateOrgId",0);
            jsonObject2.put("Number","");
            jsonObject2.put("Id",ids);
            com.alibaba.fastjson.JSONObject object = InvokeHelper.Invoke2("View","STK_MISCELLANEOUS",jsonObject2.toString(),InvokeHelper.getCook());
            ruku = JSON.toJavaObject(object,Ruku.class);
        }
        return ruku;
    }

    @Override
    public List<Map<String, String>> getRukuLei(String fId){
        return  kingCangMapper.getRukuLei(fId);
    }

    @Override
    public String fIdToWuLiao(String fId){
        JSONArray jsonArray = new JSONArray();
        List<String> list = kingCangMapper.getWuGroupOne(fId);
        if(list.size()>0){
            for(int i=0;i<list.size();i++){
                org.json.JSONObject jsonObject1 = new org.json.JSONObject();
                JSONArray jsonArray1 = new JSONArray();
                List<Map<String, String>> list1 = kingCangMapper.getWuGroupTwo(fId,list.get(i));
                if(list1.size()>0){
                    for(Map<String, String> map:list1){
                        org.json.JSONObject jsonObject2 = new org.json.JSONObject();
                        JSONArray jsonArray2 = new JSONArray();
                        List<Map<String, String>> list2 = kingCangMapper.getWuGroupThree(fId,map.get("code"));
                        if(list2.size()>0) {
                            for(Map<String, String> map2:list2){
                                org.json.JSONObject jsonObject3 = new org.json.JSONObject();
                                jsonObject3.put("id",map2.get("code"));
                                if(StringUtils.isNotEmpty(map2.get("spec"))){
                                    jsonObject3.put("name",map2.get("name")+"("+map2.get("spec")+")");
                                }else {
                                    jsonObject3.put("name", map2.get("name"));
                                }
                                jsonObject3.put("pid",map.get("code"));
                                jsonArray2.put(jsonObject3);
                            }
                        }
                        jsonObject2.put("childs",jsonArray2);
                        jsonObject2.put("id",map.get("code"));
                        jsonObject2.put("name",map.get("name"));
                        jsonObject2.put("pid",list.get(i));
                        jsonArray1.put(jsonObject2);
                    }
                }
                jsonObject1.put("childs",jsonArray1);
                jsonObject1.put("id",list.get(i));
                jsonObject1.put("name",list.get(i));
                jsonObject1.put("pid","0");
                jsonArray.put(jsonObject1);
            }
        }
        return jsonArray.toString();
    }

    @Override
    public List<Map<String, String>> getKuCuState(){
        return kingCangMapper.getKuCuState();
    }

    @Override
    public List<Map<String, String>> getZhongList(){
        return kingCangMapper.getZhongList();
    }

    @Override
    public String getSubParam(JSONObject jsonObject){
        String organ;
        JSONObject object = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        if(jsonObject.containsKey("organ")){
            organ = kingBdOrganizationMapper.fIdToCode(jsonObject.get("organ").toString());
            jsonObject.put("organCode",organ);
        }
         String x  = getObjectZhu2(jsonObject);
        return x;
    }

    @Override
    public String getSubChuParam(JSONObject jsonObject){
        String x  = getObjectZhu3(jsonObject);
        return x;
    }

    public JSONObject getObjectZhu(JSONObject jsonObject){
        JSONObject jsonObject1 = new JSONObject(new LinkedHashMap());
        JSONObject jsonObject2 = new JSONObject(new LinkedHashMap());
        JSONObject jsonObject3 = new JSONObject();
        JSONObject jsonObject4 = new JSONObject();
        JSONObject jsonObject5 = new JSONObject();
        JSONObject jsonObject6 = new JSONObject();
        JSONObject jsonObject7 = new JSONObject();
        com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();
        jsonObject3.put("FNumber",jsonObject.getString("organCode"));
        jsonObject4.put("FNumber","PRE001");   //本位币 人民币代码
        jsonObject5.put("FNUMBER","QTRKD01_SYS");   //标准入库单代码
        jsonObject6.put("FNumber",jsonObject.getString("organCode"));
        jsonObject7.put("FNUMBER",jsonObject.getString("mold"));
        if(jsonObject.containsKey("fentity")) {
            if (jsonObject.get("fentity") != null) {
                //JSONObject para= JSONObject.parseObject( jsonObject.get("fentity").toString());
                jsonArray= jsonObject.getJSONArray("fentity");

                //jsonArray = com.alibaba.fastjson.JSONArray.parseArray(jsonObject.get("fentity").toString());
            }
        }
        double jSum = Double.valueOf(jsonArray.size());
        jsonObject2.put("FID",0);
        jsonObject2.put("FStockOrgId",jsonObject3);
        jsonObject2.put("FStockDirect",jsonObject.getString("stock"));
        jsonObject2.put("FDate", DateUtil.formatDateTime(DateUtil.parse(jsonObject.getString("current"))));
        jsonObject2.put("FOwnerTypeIdHead",jsonObject.getString("cargo"));
        jsonObject2.put("FBaseCurrId",jsonObject4);
        jsonObject2.put("FBillTypeID",jsonObject5);
        jsonObject2.put("FOwnerIdHead",jsonObject6);
        jsonObject2.put("F_YMJT_Base1",jsonObject7);
        jsonObject2.put("F_YMJT_CheckBox",true);
        jsonObject2.put("F_YMJT_CheckBox1",true);
        jsonObject2.put("F_YMJT_Qty1",jSum);
        jsonObject2.put("F_YMJT_Qty11",jSum);

        JSONArray jsonArray1 = getObjectWuList(jsonObject);
        jsonObject2.put("FEntity",jsonArray1.toString());
        jsonObject1.put("Model",jsonObject2);
        String jsonString = JSONObject.toJSONString(jsonObject1);
        String jsonString2 = jsonObject1.toString();
        return jsonObject1;
    }

    public JSONArray getObjectWuList(JSONObject jsonObject){
        JSONArray jsonArray = new JSONArray();
        if(jsonObject.containsKey("fentity")){
            if(jsonObject.get("fentity")!=null){
                com.alibaba.fastjson.JSONArray ja = jsonObject.getJSONArray("fentity");
                for(int i=0;i<ja.size();i++) {
                    ArrayList sja = (ArrayList) ja.get(i);
                    JSONObject jsonOne = (JSONObject) JSON.toJSON(sja.get(0));
                    Map jsonObject0 = new LinkedHashMap();
                    JSONObject jsonObject1 = new JSONObject(new LinkedHashMap());
                    JSONObject jsonObject2 = new JSONObject(new LinkedHashMap());
                    JSONObject jsonObject3 = new JSONObject(new LinkedHashMap());
                    JSONObject jsonObject4 = new JSONObject(new LinkedHashMap());
                    JSONObject jsonObject5 = new JSONObject(new LinkedHashMap());
                    JSONObject jsonObject6 = new JSONObject(new LinkedHashMap());
                    JSONObject jsonObject7 = new JSONObject(new LinkedHashMap());
                    JSONObject jsonObject8 = new JSONObject(new LinkedHashMap());
                    JSONObject jsonObject9 = new JSONObject(new LinkedHashMap());
                    JSONObject jsonObject10 = new JSONObject(new LinkedHashMap());
                    JSONObject jsonObject11 = new JSONObject(new LinkedHashMap());
                    JSONObject jsonObject12 = new JSONObject(new LinkedHashMap());

                    com.alibaba.fastjson.JSONArray jsonArray1 = jsonOne.getJSONArray("name");
                    jsonObject1.put("FNUMBER",jsonArray1.getString(jsonArray1.size()-1));   //物料编码
                    jsonObject2.put("FNumber",jsonArray1.getString(jsonArray1.size()-1));    //物料编码
                    jsonObject3.put("FNumber","箱");     //辅助单位

                    com.alibaba.fastjson.JSONArray jsonArray2 = jsonOne.getJSONArray("can");
                    if(jsonArray2.size()>1){
                        jsonObject5.put("FNumber",jsonArray2.getString(1));      //仓位编号
                        String cwh = kingCangMapper.getCwCan(jsonArray2.getString(0));
                        jsonObject6.put("FSTOCKLOCID__"+cwh,jsonObject5);
                    }
                    jsonObject4.put("FNumber",jsonArray2.getString(0));      //仓库编号
                    jsonObject7.put("FNumber",kingCangMapper.getWuUnit(jsonArray1.getString(jsonArray1.size()-1),jsonObject.getString("organ")));       //入库单位
                    if(StringUtils.isNotEmpty(jsonOne.getString("ku"))) {
                        jsonObject8.put("FNumber", jsonOne.getString("ku"));
                    }else {
                        jsonObject8.put("FNumber", "KCZT098");   //默认库存等级
                    }
                    jsonObject9.put("FNumber",jsonOne.getString("xing"));      //形态代码
                    jsonObject10.put("FAUXPROPID__FF100001",jsonObject9);
                    jsonObject11.put("FNumber",jsonObject.getString("organCode"));       //组织机构编码
                    jsonObject0.put("F_YMJT_Base4",jsonObject1);
                    jsonObject0.put("FMATERIALID",jsonObject2);
                    double jSum = Double.valueOf(jsonOne.getString("number"));
                    jsonObject0.put("FExtAuxUnitQty",jSum);     //辅助入库数量
                    jsonObject0.put("FExtAuxUnitId",jsonObject3);
                    jsonObject0.put("F_YMJT_Integer1",1);           //转换率
                    jsonObject0.put("FQty",jSum);                    //入库数量
                    jsonObject0.put("FSTOCKID",jsonObject4);
                    jsonObject0.put("FStockLocId",jsonObject6);
                    jsonObject0.put("FUnitID",jsonObject7);
                    jsonObject0.put("FSTOCKSTATUSID",jsonObject8);
                    jsonObject0.put("F_YMJT_CheckBox2",false);
                    jsonObject0.put("FAuxPropId",jsonObject10);
                    jsonObject0.put("FPRODUCEDATE", DateUtil.formatDateTime(DateUtil.parse(jsonObject.getString("current"))));         //入库日期String
                    jsonObject0.put("F_YMJT_Integer",Integer.valueOf(jsonOne.getString("bao")));       //保质期
                    jsonObject0.put("FOWNERTYPEID",jsonObject.getString("cargo"));
                    jsonObject0.put("FOWNERID",jsonObject11);
                    jsonObject0.put("F_YMJT_Qty2",1.0);           //转换率
                    jsonObject0.put("FKEEPERTYPEID","BD_KeeperOrg");
                    jsonObject0.put("F_YMJT_Qty3",1.0);           //转换率
                    jsonObject0.put("FKEEPERID",jsonObject11);
                    jsonObject0.put("F_YMJT_CheckBox3",false);
                    jsonArray.put(jsonObject0);
                }
            }
        }
        return jsonArray;
    }


    public String getObjectZhu2(JSONObject jsonObject){
        Map<String, Object> jsonObject1 = new LinkedHashMap();
        Map<String, Object> jsonObject2 = new LinkedHashMap();
        Map<String, String> jsonObject3 = new LinkedHashMap();
        Map<String, String> jsonObject4 = new LinkedHashMap();
        Map<String, String> jsonObject5 = new LinkedHashMap();
        Map<String, String> jsonObject6 = new LinkedHashMap();
        Map<String, String> jsonObject7 = new LinkedHashMap();
        com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();
        jsonObject3.put("FNumber",jsonObject.getString("organCode"));
        jsonObject4.put("FNumber","PRE001");   //本位币 人民币代码
        jsonObject5.put("FNUMBER","QTRKD01_SYS");   //标准入库单代码
        jsonObject6.put("FNumber",jsonObject.getString("organCode"));
        jsonObject7.put("FNUMBER",jsonObject.getString("mold"));
        if(jsonObject.containsKey("fentity")) {
            if (jsonObject.get("fentity") != null) {
                jsonArray= jsonObject.getJSONArray("fentity");
            }
        }
        double jSum = Double.valueOf(jsonArray.size());
        jsonObject2.put("FID",0);
        jsonObject2.put("FStockOrgId",jsonObject3);
        jsonObject2.put("FStockDirect",jsonObject.getString("stock"));
        jsonObject2.put("FDate", DateUtil.formatDateTime(DateUtil.parse(jsonObject.getString("current"))));
        jsonObject2.put("FOwnerTypeIdHead",jsonObject.getString("cargo"));
        jsonObject2.put("FBaseCurrId",jsonObject4);
        jsonObject2.put("FBillTypeID",jsonObject5);
        jsonObject2.put("FOwnerIdHead",jsonObject6);
        jsonObject2.put("F_YMJT_Base1",jsonObject7);
        jsonObject2.put("F_YMJT_CheckBox",true);
        jsonObject2.put("F_YMJT_CheckBox1",true);
        jsonObject2.put("F_YMJT_Qty1",jSum);
        jsonObject2.put("F_YMJT_Qty11",jSum);
        List<Map<String, Object>> jsonArray1 = getObjectWuList2Two(jsonObject);
        jsonObject2.put("FEntity",jsonArray1);
        jsonObject1.put("Model",jsonObject2);
//        String jsonString = JSONObject.toJSONString(jsonObject1);
//        String jsonString2 = jsonObject1.toString();
        String x =JSONObject.toJSONString(jsonObject1);
        return x;
    }

    public List<Map<String, Object>> getObjectWuList2(JSONObject jsonObject){
       List<Map<String, Object>> jsonArray = new ArrayList<>();
        if(jsonObject.containsKey("fentity")){
            if(jsonObject.get("fentity")!=null){
                com.alibaba.fastjson.JSONArray ja = jsonObject.getJSONArray("fentity");
                for(int i=0;i<ja.size();i++) {
                    ArrayList sja = (ArrayList) ja.get(i);
                    JSONObject jsonOne = (JSONObject) JSON.toJSON(sja.get(0));
                    Map jsonObject0 = new LinkedHashMap();
                    Map<String, String> jsonObject1 = new LinkedHashMap();
                    Map<String, String> jsonObject2 =new LinkedHashMap();
                    Map<String, String> jsonObject3 = new LinkedHashMap();
                    Map<String, String> jsonObject4 = new LinkedHashMap();
                    Map<String, String> jsonObject5 = new LinkedHashMap();
                    Map<String, Object> jsonObject6 = new LinkedHashMap();
                    Map<String, String> jsonObject7 = new LinkedHashMap();
                    Map<String, String> jsonObject8 = new LinkedHashMap();
                    Map<String, String> jsonObject9 = new LinkedHashMap();
                    Map<String, Object> jsonObject10 = new LinkedHashMap();
                    Map<String, String> jsonObject11 = new LinkedHashMap();
                    Map<String, String> jsonObject12 = new LinkedHashMap();

                    com.alibaba.fastjson.JSONArray jsonArray1 = jsonOne.getJSONArray("name");
                    jsonObject1.put("FNUMBER",jsonArray1.getString(jsonArray1.size()-1));   //物料编码
                    jsonObject2.put("FNumber",jsonArray1.getString(jsonArray1.size()-1));    //物料编码
                    jsonObject3.put("FNumber","箱");     //辅助单位

                    com.alibaba.fastjson.JSONArray jsonArray2 = jsonOne.getJSONArray("can");
                    if(jsonArray2.size()>1){
                        jsonObject5.put("FNumber",jsonArray2.getString(1));      //仓位编号
                        String cwh = kingCangMapper.getCwCan(jsonArray2.getString(0));
                        jsonObject6.put("FSTOCKLOCID__"+cwh,jsonObject5);
                    }
                    jsonObject4.put("FNumber",jsonArray2.getString(0));      //仓库编号
                    jsonObject7.put("FNumber",kingCangMapper.getWuUnit(jsonArray1.getString(jsonArray1.size()-1),jsonObject.getString("organ")));       //入库单位
                    if(StringUtils.isNotEmpty(jsonOne.getString("ku"))) {
                        jsonObject8.put("FNumber", jsonOne.getString("ku"));
                    }else {
                        jsonObject8.put("FNumber", "KCZT098");   //默认库存等级
                    }
                    jsonObject9.put("FNumber",jsonOne.getString("xing"));      //形态代码
                    jsonObject10.put("FAUXPROPID__FF100001",jsonObject9);
                    jsonObject11.put("FNumber",jsonObject.getString("organCode"));       //组织机构编码
                    jsonObject0.put("F_YMJT_Base4",jsonObject1);
                    jsonObject0.put("FMATERIALID",jsonObject2);
                    double jSum = Double.valueOf(jsonOne.getString("number"));
                    jsonObject0.put("FExtAuxUnitQty",jSum);     //辅助入库数量
//                    jsonObject0.put("FExtAuxUnitId",jsonObject3);
                    jsonObject0.put("F_YMJT_Integer1",1);           //转换率
                    jsonObject0.put("FQty",jSum);                    //入库数量
                    jsonObject0.put("FSTOCKID",jsonObject4);
                    if(jsonArray2.size()>1) {
                        jsonObject0.put("FStockLocId", jsonObject6);
                    }
                    jsonObject0.put("FUnitID",jsonObject7);
                    jsonObject0.put("FSTOCKSTATUSID",jsonObject8);
                    jsonObject0.put("F_YMJT_CheckBox2",false);
                    jsonObject0.put("FAuxPropId",jsonObject10);
                    if(StringUtils.isNotBlank(jsonOne.getString("sheng"))) {
                        jsonObject0.put("FPRODUCEDATE", DateUtil.formatDateTime(DateUtil.parse(jsonOne.getString("sheng"))));         //入库日期String
                    }
                    if(StringUtils.isNotBlank(jsonOne.getString("bao"))) {
                        jsonObject0.put("F_YMJT_Integer", Integer.valueOf(jsonOne.getString("bao")));       //保质期
                    }
                    jsonObject0.put("FOWNERTYPEID",jsonObject.getString("cargo"));
                    jsonObject0.put("FOWNERID",jsonObject11);
                    jsonObject0.put("F_YMJT_Qty2",1.0);           //转换率
                    jsonObject0.put("FKEEPERTYPEID","BD_KeeperOrg");
                    jsonObject0.put("F_YMJT_Qty3",1.0);           //转换率
                    jsonObject0.put("FKEEPERID",jsonObject11);
                    jsonObject0.put("F_YMJT_CheckBox3",false);
                    jsonArray.add(jsonObject0);
                }
            }
        }
        return jsonArray;
    }


    public List<Map<String, Object>> getObjectWuList2Two(JSONObject jsonObject){
        List<Map<String, Object>> jsonArray = new ArrayList<>();
        if(jsonObject.containsKey("fentity")){
            if(jsonObject.get("fentity")!=null){
                com.alibaba.fastjson.JSONArray ja = jsonObject.getJSONArray("fentity");
                for(int i=0;i<ja.size();i++) {
                    ArrayList sja = (ArrayList) ja.get(i);
                    JSONObject jsonOne = (JSONObject) JSON.toJSON(sja.get(0));
                    Map jsonObject0 = new LinkedHashMap();
                    Map<String, String> jsonObject1 = new LinkedHashMap();
                    Map<String, String> jsonObject2 =new LinkedHashMap();
                    Map<String, String> jsonObject3 = new LinkedHashMap();
                    Map<String, String> jsonObject4 = new LinkedHashMap();
                    Map<String, String> jsonObject5 = new LinkedHashMap();
                    Map<String, Object> jsonObject6 = new LinkedHashMap();
                    Map<String, String> jsonObject7 = new LinkedHashMap();
                    Map<String, String> jsonObject8 = new LinkedHashMap();
                    Map<String, String> jsonObject9 = new LinkedHashMap();
                    Map<String, Object> jsonObject10 = new LinkedHashMap();
                    Map<String, String> jsonObject11 = new LinkedHashMap();
                    Map<String, String> jsonObject12 = new LinkedHashMap();

                    //com.alibaba.fastjson.JSONArray jsonArray1 = jsonOne.getJSONArray("name");
                    jsonObject1.put("FNUMBER",jsonOne.getString("name"));   //物料编码
                    jsonObject2.put("FNumber",jsonOne.getString("name"));    //物料编码


                    com.alibaba.fastjson.JSONArray jsonArray2 = jsonOne.getJSONArray("can");
                    if(jsonArray2.size()>1){
                        jsonObject5.put("FNumber",jsonArray2.getString(1));      //仓位编号
                        String cwh = kingCangMapper.getCwCan(jsonArray2.getString(0));
                        jsonObject6.put("FSTOCKLOCID__"+cwh,jsonObject5);
                    }
                    jsonObject4.put("FNumber",jsonArray2.getString(0));      //仓库编号
                    jsonObject7.put("FNumber",kingCangMapper.getWuUnit(jsonOne.getString("name"),jsonObject.getString("organ")));       //入库单位
                    if(StringUtils.isNotEmpty(jsonOne.getString("ku"))) {
                        jsonObject8.put("FNumber", jsonOne.getString("ku"));
                    }else {
                        jsonObject8.put("FNumber", "KCZT098");   //默认库存等级
                    }

                    jsonObject11.put("FNumber",jsonObject.getString("organCode"));       //组织机构编码
                    jsonObject0.put("F_YMJT_Base4",jsonObject1);
                    jsonObject0.put("FMATERIALID",jsonObject2);
                    double jSum = Double.valueOf(jsonOne.getString("number"));
                    if(jsonOne.containsKey("xing")){
                        jsonObject3.put("FNumber",kingCangMapper.getWuFuUnit(jsonOne.getString("name"),jsonObject.getString("organ")));     //辅助单位
                        jsonObject0.put("FExtAuxUnitQty",jSum);     //辅助入库数量
                        jsonObject0.put("FExtAuxUnitId",jsonObject3);
                    }
                    jsonObject0.put("F_YMJT_Integer1",1);           //转换率
                    jsonObject0.put("FQty",jSum);                    //入库数量
                    jsonObject0.put("FSTOCKID",jsonObject4);
                    if(jsonArray2.size()>1) {
                        jsonObject0.put("FStockLocId", jsonObject6);
                    }
                    jsonObject0.put("FUnitID",jsonObject7);
                    jsonObject0.put("FSTOCKSTATUSID",jsonObject8);
                    jsonObject0.put("F_YMJT_CheckBox2",false);
                    if(jsonOne.containsKey("xing")) {
                        jsonObject9.put("FNumber",jsonOne.getString("xing"));      //形态代码
                        jsonObject10.put("FAUXPROPID__FF100001",jsonObject9);
                        jsonObject0.put("FAuxPropId", jsonObject10);
                    }
                    if(StringUtils.isNotBlank(jsonOne.getString("sheng"))) {
                        jsonObject0.put("FPRODUCEDATE", DateUtil.formatDateTime(DateUtil.parse(jsonOne.getString("sheng"))));         //入库日期String
                    }
                    if(StringUtils.isNotBlank(jsonOne.getString("bao"))) {
                        jsonObject0.put("F_YMJT_Integer", Integer.valueOf(jsonOne.getString("bao")));       //保质期
                    }
                    jsonObject0.put("FOWNERTYPEID",jsonObject.getString("cargo"));
                    jsonObject0.put("FOWNERID",jsonObject11);
                    jsonObject0.put("F_YMJT_Qty2",1.0);           //转换率
                    jsonObject0.put("FKEEPERTYPEID","BD_KeeperOrg");
                    jsonObject0.put("F_YMJT_Qty3",1.0);           //转换率
                    jsonObject0.put("FKEEPERID",jsonObject11);
                    jsonObject0.put("F_YMJT_CheckBox3",false);
                    jsonArray.add(jsonObject0);
                }
            }
        }
        return jsonArray;
    }

    @Override
    public String selectWuliaoCp(String fCode){
        return  kingCangMapper.selectWuliaoCp(fCode);
    }

    @Override
    public List<Map<String, Object>> getQitaRuArry(List<KingZjRk> list){
        List<Map<String, Object>>mapList = new LinkedList<>();
        if(list.size()>0){
            List<KingZjRk> listOne = new ArrayList<>();
            List<KingZjRk> listTwo = new ArrayList<>();
            List<KingZjRk> listThree = new ArrayList<>();
            for(KingZjRk kingZjRk :list){
                if(kingZjRk.getfState().equals("B")){
                    kingZjRk.setFlag1(false);
                    kingZjRk.setFlag2(true);
                    kingZjRk.setFlag3(false);
                    listTwo.add(kingZjRk);
                }else if (kingZjRk.getfState().equals("C")){
                    kingZjRk.setFlag1(false);
                    kingZjRk.setFlag2(false);
                    kingZjRk.setFlag3(true);
                    listThree.add(kingZjRk);
                }else {
                        kingZjRk.setFlag1(true);
                        kingZjRk.setFlag2(false);
                        kingZjRk.setFlag3(false);
                        listOne.add(kingZjRk);
                }
            }
            Map<String, Object> jsonOne = new LinkedHashMap<>();
            jsonOne.put("list",listOne);
            Map<String, Object> jsonTwo = new LinkedHashMap<>();
            jsonTwo.put("list",listTwo);
            Map<String, Object> jsonThree = new LinkedHashMap<>();
            jsonThree.put("list",listThree);
            mapList.add(jsonOne);
            mapList.add(jsonTwo);
            mapList.add(jsonThree);
        }
        return mapList;
    }

    @Override
    public String getSubmitParm(String fCode){
        Map<String, Object> map = new LinkedHashMap<>();
        List<String> list = new ArrayList<>();
        list.add(fCode);
        map.put("Numbers",list);
        return JSONObject.toJSONString(map);
    }

    @Override
    public List<Map<String, String>> getCellDetail(String fId){
        return kingCangMapper.getCellDetail(fId);
    }

    @Override
    public List<StkMisc> useridToSTKchuList(String userId){
        List<StkMisc> list = kingCangMapper.useridToSTKchuList(userId);
        return list;
    }

    @Override
    public List<KingZjRk> getUserStkChu(List<StkMisc> list) throws Exception {
        List<KingZjRk> list1 = new ArrayList<>();
        if(list.size()>0){
            for(StkMisc stkMisc:list){
                KingZjRk kingZjRk = new KingZjRk();
                BeanUtils.copyProperties(stkMisc,kingZjRk);
                kingZjRk.setfWuliao(idToStkmisChuChildList(stkMisc.getfId()));
                list1.add(kingZjRk);
            }
        }
        return list1;
    }


    @Override
    public String fIdToWuLiaoKuCun(String fId){
        JSONArray jsonArray = new JSONArray();
        List<String> list = kingCangMapper.getWuKuCunGroupOne(fId);
        if(list.size()>0){
            for(int i=0;i<list.size();i++){
                org.json.JSONObject jsonObject1 = new org.json.JSONObject();
                JSONArray jsonArray1 = new JSONArray();
                List<Map<String, String>> list1 = kingCangMapper.getWuKuCunGroupTwo(fId,list.get(i));
                if(list1.size()>0){
                    for(Map<String, String> map:list1){
                        org.json.JSONObject jsonObject2 = new org.json.JSONObject();
                        JSONArray jsonArray2 = new JSONArray();
                        List<Map<String, String>> list2 = kingCangMapper.getWuKuCunGroupThree(fId,map.get("code"));
                        if(list2.size()>0) {
                            for(Map<String, String> map2:list2){
                                org.json.JSONObject jsonObject3 = new org.json.JSONObject();
                                jsonObject3.put("id",map2.get("code"));
                                if(StringUtils.isNotEmpty(map2.get("spec"))){
                                    jsonObject3.put("name",map2.get("name")+"("+map2.get("spec")+")");
                                }else {
                                    jsonObject3.put("name", map2.get("name"));
                                }
                                jsonObject3.put("pid",map.get("code"));
                                jsonArray2.put(jsonObject3);
                            }
                        }
                        jsonObject2.put("childs",jsonArray2);
                        jsonObject2.put("id",map.get("code"));
                        jsonObject2.put("name",map.get("name"));
                        jsonObject2.put("pid",list.get(i));
                        jsonArray1.put(jsonObject2);
                    }
                }
                jsonObject1.put("childs",jsonArray1);
                jsonObject1.put("id",list.get(i));
                jsonObject1.put("name",list.get(i));
                jsonObject1.put("pid","0");
                jsonArray.put(jsonObject1);
            }
        }
        return jsonArray.toString();
    }

    @Override
    public String getKuCunCanList(String fId,String fCode){
        List<Map<String, String>> list = kingCangMapper.getKuCunCanList(fId,fCode);
        List<Map<String, Object>> mapList =new ArrayList<>();
        if(list.size()>0){
            for(Map<String, String> map :list){
                Map<String, Object> map1 = new HashMap<>();
                List<Map<String, String>> list1 = kingCangMapper.getKuCunCanW(fId,fCode,map.get("id"));
                List<Map<String, String>> listmap = new ArrayList<>();
                if(list1!=null) {
                    for(Map<String, String> map2:list1){
                        String canshu = kingCangMapper.getCwCan(map2.get("fCode"));
                        Map<String, String> map3 = kingCangMapper.getCw(canshu,String.valueOf(map2.get("fId")));
                        if(map3!=null){
                            map3.put("pid",map2.get("fCode"));
                            listmap.add(map3);
                        }
                    }
                }
                map1.putAll(map);
                map1.put("pid","0");
                if(listmap.size()>0) {
                    map1.put("childs", listmap);
                }
                mapList.add(map1);
            }

        }
        return JSONObject.toJSONString(mapList);
    }

    @Override
    public String getFloatNumber(FloatNumber floatNumber){
        if(StringUtils.isNotBlank(floatNumber.getfId())){
            floatNumber.setfId(kingBdOrganizationMapper.fCodeToId(floatNumber.getfId()));
        }
        if(StringUtils.isNotBlank(floatNumber.getfCangWei())){
            String Canshu = kingCangMapper.getCwCan(floatNumber.getfCangWei());
            floatNumber.setfCangWei(kingCangMapper.getCwFid(Canshu,floatNumber.getfCangWei()));
        }
        List<String> list = kingCangMapper.getFloatNumber(floatNumber);
        List<Map<String, String>> mapList = new ArrayList<>();
        if(list.size()>0){
            for(int i=0;i<list.size();i++){
                Map<String, String> map = new HashMap<>();
                map.put("value",list.get(i));
                map.put("laber",list.get(i));
                mapList.add(map);
            }
        }
        return JSONObject.toJSONString(mapList);
    }

    @Override
    public Integer getKuCunNum(FloatNumber floatNumber){
        if(StringUtils.isNotBlank(floatNumber.getfId())){
            floatNumber.setfId(kingBdOrganizationMapper.fCodeToId(floatNumber.getfId()));
        }
        if(StringUtils.isNotBlank(floatNumber.getfCangWei())){
            String Canshu = kingCangMapper.getCwCan(floatNumber.getfCangWei());
            floatNumber.setfCangWei(kingCangMapper.getCwFid(Canshu,floatNumber.getfCangWei()));
        }
        BigDecimal bigDecimal = kingCangMapper.getKuCunNum(floatNumber);
        return bigDecimal.intValue();
    }

    public String getObjectZhu3(JSONObject jsonObject){
        Map<String, Object> jsonObject1 = new LinkedHashMap();
        Map<String, Object> jsonObject2 = new LinkedHashMap();
        Map<String, String> jsonObject3 = new LinkedHashMap();
        Map<String, String> jsonObject4 = new LinkedHashMap();
        Map<String, String> jsonObject5 = new LinkedHashMap();
        Map<String, String> jsonObject6 = new LinkedHashMap();
        Map<String, String> jsonObject7 = new LinkedHashMap();
        Map<String, String> jsonObject8 = new LinkedHashMap();
        com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();

        com.alibaba.fastjson.JSONArray jsonArray2 = jsonObject.getJSONArray("organ");
        jsonObject3.put("FNumber",jsonArray2.getString(0));
        jsonObject6.put("FNumber",jsonArray2.getString(0));
        jsonObject7.put("FNumber",jsonArray2.getString(0));
        jsonObject4.put("FNumber","PRE001");   //本位币 人民币代码
        jsonObject5.put("FNUMBER","QTCKD01_SYS");   //标准出库单代码
        jsonObject8.put("FNumber",jsonArray2.getString(1));
        if(jsonObject.containsKey("fentity")) {
            if (jsonObject.get("fentity") != null) {
                jsonArray= jsonObject.getJSONArray("fentity");
            }
        }
        double jSum = Double.valueOf(jsonArray.size());
        jsonObject2.put("FID",0);
        jsonObject2.put("FBillTypeID",jsonObject5);
        jsonObject2.put("FStockOrgId",jsonObject3);
        jsonObject2.put("FPickOrgId",jsonObject6);
        jsonObject2.put("FStockDirect","GENERAL");  //库存方向，默认普通GENERAL
        jsonObject2.put("FDate", DateUtil.formatDateTime(DateUtil.parse(jsonObject.getString("current"))));
        jsonObject2.put("FDeptId",jsonObject8);   //部门编码
        jsonObject2.put("FOwnerTypeIdHead","BD_OwnerOrg"); //货主类型 默认
        jsonObject2.put("FOwnerIdHead",jsonObject7);
        jsonObject2.put("FBaseCurrId",jsonObject4);
        jsonObject2.put("F_YMJT_Integer",329063);
        jsonObject2.put("F_YMJT_Qty1",jSum);
        jsonObject2.put("F_YMJT_CheckBox",true);
        jsonObject2.put("F_YMJT_CheckBox1",true);
        jsonObject2.put("F_YMJT_Qty3",jSum);
        jsonObject2.put("F_YMJT_Combo1",jSum);

        List<Map<String, Object>> jsonArray1 = getObjectWuList3Two(jsonObject);
        if(jsonArray1==null){
            return "null";
        }
        jsonObject2.put("FEntity",jsonArray1);
        jsonObject1.put("Model",jsonObject2);
//        String jsonString = JSONObject.toJSONString(jsonObject1);
//        String jsonString2 = jsonObject1.toString();
        String x =JSONObject.toJSONString(jsonObject1);
        return x;
    }

    public List<Map<String, Object>> getObjectWuList3(JSONObject jsonObject){
        com.alibaba.fastjson.JSONArray jsonOrgan = jsonObject.getJSONArray("organ");
        List<Map<String, Object>> jsonArray = new ArrayList<>();
        if(jsonObject.containsKey("fentity")){
            if(jsonObject.get("fentity")!=null){
                com.alibaba.fastjson.JSONArray ja = jsonObject.getJSONArray("fentity");
                for(int i=0;i<ja.size();i++) {
                    ArrayList sja = (ArrayList) ja.get(i);
                    JSONObject jsonOne = (JSONObject) JSON.toJSON(sja.get(0));
                    Map jsonObject0 = new LinkedHashMap();
                    Map<String, String> jsonObject1 = new LinkedHashMap();
                    Map<String, String> jsonObject2 =new LinkedHashMap();
                    Map<String, String> jsonObject3 = new LinkedHashMap();
                    Map<String, String> jsonObject4 = new LinkedHashMap();
                    Map<String, String> jsonObject5 = new LinkedHashMap();
                    Map<String, Object> jsonObject6 = new LinkedHashMap();
                    Map<String, String> jsonObject7 = new LinkedHashMap();
                    Map<String, String> jsonObject8 = new LinkedHashMap();
                    Map<String, String> jsonObject9 = new LinkedHashMap();
                    Map<String, Object> jsonObject10 = new LinkedHashMap();
                    Map<String, String> jsonObject11 = new LinkedHashMap();
                    Map<String, String> jsonObject12 = new LinkedHashMap();
                    Map<String, String> jsonObject13 = new LinkedHashMap();
                    Map<String, String> jsonObject14 = new LinkedHashMap();


                    com.alibaba.fastjson.JSONArray jsonArray1 = jsonOne.getJSONArray("name");
                    com.alibaba.fastjson.JSONArray jsonArray2 = jsonOne.getJSONArray("can");
                    FloatNumber floatNumber = new FloatNumber();
                    floatNumber.setfId(kingBdOrganizationMapper.fCodeToId(jsonOrgan.getString(0)));
                    floatNumber.setcPCode(jsonArray1.getString(jsonArray1.size()-1));
                    if(jsonArray2.size()>1){
                        String Canshu = kingCangMapper.getCwCan(jsonArray2.getString(1));
                        floatNumber.setfCangWei(kingCangMapper.getCwFid(Canshu,jsonArray2.getString(1)));
//                       floatNumber.setfCangWei(kingBdCangwMapper.fCodeToId(jsonArray2.getString(1)));      //仓位编号
                    }else {
                        floatNumber.setfCang(jsonArray2.getString(0));
                    }
                    floatNumber.setfPi(jsonOne.getString("pi"));
                    KuCunParm kuCunParm = kingCangMapper.getKucunFu(floatNumber);
                    if(kuCunParm==null){
                        return jsonArray;
                    }



                    jsonObject1.put("FNUMBER",jsonArray1.getString(jsonArray1.size()-1));   //物料编码
                    jsonObject2.put("FNumber",jsonArray1.getString(jsonArray1.size()-1));    //物料编码



                    if(jsonArray2.size()>1){
                        jsonObject5.put("FNumber",jsonArray2.getString(1));      //仓位编号
                        String cwh = kingCangMapper.getCwCan(jsonArray2.getString(0));
                        jsonObject6.put("FSTOCKLOCID__"+cwh,jsonObject5);
                    }
                    jsonObject4.put("FNumber",jsonArray2.getString(0));      //仓库编号
                    jsonObject7.put("FNumber",kingCangMapper.getWuUnit(jsonArray1.getString(jsonArray1.size()-1),kingBdOrganizationMapper.fCodeToId(jsonOrgan.getString(0))));       //入库单位
                    jsonObject12.put("FNumber",kingCangMapper.getWuUnit(jsonArray1.getString(jsonArray1.size()-1),kingBdOrganizationMapper.fCodeToId(jsonOrgan.getString(0))));       //入库单位
                    jsonObject8.put("FNumber", "KCZT098");   //默认库存等级

                    jsonObject11.put("FNumber",jsonOrgan.getString(0));       //组织机构编码

                   // jsonObject12.put("FNumber",jsonObject.getString("organCode"));
                    jsonObject13.put("FNumber",jsonOne.getString("pi"));
                    jsonObject14.put("FNumber",jsonOrgan.getString(0));       //组织机构编码

                    jsonObject0.put("FMaterialId",jsonObject2);
                    jsonObject0.put("FSTOCKID",jsonObject4);
                    if(jsonArray2.size()>1) {
                        jsonObject0.put("FStockLocId", jsonObject6);
                    }
                    jsonObject0.put("FLot",jsonObject13);
                    jsonObject0.put("FStockStatusId",jsonObject8);
                    if(StringUtils.isNotBlank(kuCunParm.getfStatus())) {
                        jsonObject9.put("FNumber", kuCunParm.getfStatus());      //形态代码
                        jsonObject10.put("FAUXPROPID__FF100001", jsonObject9);
                        jsonObject0.put("FAuxPropId", jsonObject10);
                    }
                    if(jsonOne.containsKey("numberOne")){
                        if(jsonOne.getString("numberOne")!=null){
                            double jSum = Double.valueOf(jsonOne.getString("numberOne"));
                            jsonObject0.put("FExtAuxUnitQty",jSum);     //辅助入库数量
                        }
                    }
                    if(StringUtils.isNotBlank(kuCunParm.getfDanWei())){
                        jsonObject3.put("FNumber",kuCunParm.getfDanWei());     //辅助单位
                        jsonObject0.put("FExtAuxUnitId",jsonObject3);
                    }

                    if(kuCunParm.getfNum()!=null) {
                        jsonObject0.put("F_YMJT_Decimal", kuCunParm.getfNum().setScale(1).toString());           //转换率
                    }
                    double jSum2 = Double.valueOf(jsonOne.getString("number"));
                    jsonObject0.put("FQty",jSum2);                    //入库数量
                    jsonObject0.put("FUnitID",jsonObject7);
                    if(StringUtils.isNotBlank(kuCunParm.getfDateFirst())) {
                        jsonObject0.put("FProduceDate", DateUtil.formatDateTime(DateUtil.parse(kuCunParm.getfDateFirst())));
                    }
                    jsonObject0.put("FBaseUnitId",jsonObject12);
                    if(StringUtils.isNotBlank(kuCunParm.getfOwnId())) {
                        jsonObject0.put("FOWNERTYPEID", kuCunParm.getfOwnId());
                    }
                    if(StringUtils.isNotBlank(kuCunParm.getfKeepId())) {
                        jsonObject0.put("FKEEPERTYPEID", kuCunParm.getfKeepId());
                    }
                    jsonObject0.put("FKEEPERID",jsonObject11);
                    jsonObject0.put("FDistribution",false);
                    jsonObject0.put("FOWNERID",jsonObject14);
                    jsonObject0.put("F_YMJT_Qty2",1.0);           //转换率
                    jsonObject0.put("F_YMJT_Qty4",1.0);           //转换率
                    jsonObject0.put("F_YMJT_CheckBox2",false);
                    jsonObject0.put("F_YMJT_Text1",jsonObject.getString("mold"));          //单据类型
                    jsonObject0.put("F_YMJT_CheckBox3",false);
                    jsonArray.add(jsonObject0);
                }
            }
        }
        return jsonArray;
    }

    public List<Map<String, Object>> getObjectWuList3Two(JSONObject jsonObject){
        com.alibaba.fastjson.JSONArray jsonOrgan = jsonObject.getJSONArray("organ");
        List<Map<String, Object>> jsonArray = new ArrayList<>();
        if(jsonObject.containsKey("fentity")){
            if(jsonObject.get("fentity")!=null){
                com.alibaba.fastjson.JSONArray ja = jsonObject.getJSONArray("fentity");
                for(int i=0;i<ja.size();i++) {
                    ArrayList sja = (ArrayList) ja.get(i);
                    JSONObject jsonOne = (JSONObject) JSON.toJSON(sja.get(0));
                    Map jsonObject0 = new LinkedHashMap();
                    Map<String, String> jsonObject1 = new LinkedHashMap();
                    Map<String, String> jsonObject2 =new LinkedHashMap();
                    Map<String, String> jsonObject3 = new LinkedHashMap();
                    Map<String, String> jsonObject4 = new LinkedHashMap();
                    Map<String, String> jsonObject5 = new LinkedHashMap();
                    Map<String, Object> jsonObject6 = new LinkedHashMap();
                    Map<String, String> jsonObject7 = new LinkedHashMap();
                    Map<String, String> jsonObject8 = new LinkedHashMap();
                    Map<String, String> jsonObject9 = new LinkedHashMap();
                    Map<String, Object> jsonObject10 = new LinkedHashMap();
                    Map<String, String> jsonObject11 = new LinkedHashMap();
                    Map<String, String> jsonObject12 = new LinkedHashMap();
                    Map<String, String> jsonObject13 = new LinkedHashMap();
                    Map<String, String> jsonObject14 = new LinkedHashMap();


                    //com.alibaba.fastjson.JSONArray jsonArray1 = jsonOne.getJSONArray("name");
                    com.alibaba.fastjson.JSONArray jsonArray2 = jsonOne.getJSONArray("can");
                    FloatNumber floatNumber = new FloatNumber();
                    floatNumber.setfId(kingBdOrganizationMapper.fCodeToId(jsonOrgan.getString(0)));
                    floatNumber.setcPCode(jsonOne.getString("name"));
                    if(jsonArray2.size()>1){
                        String Canshu = kingCangMapper.getCwCan(jsonArray2.getString(1));
                        floatNumber.setfCangWei(kingCangMapper.getCwFid(Canshu,jsonArray2.getString(1)));
//                       floatNumber.setfCangWei(kingBdCangwMapper.fCodeToId(jsonArray2.getString(1)));      //仓位编号
                    }else {
                        floatNumber.setfCang(jsonArray2.getString(0));
                    }
                    floatNumber.setfPi(jsonOne.getString("pi"));
                    KuCunParm kuCunParm = kingCangMapper.getKucunFu(floatNumber);
                    if(kuCunParm==null){
                        return jsonArray;
                    }



                    jsonObject1.put("FNUMBER",jsonOne.getString("name"));   //物料编码
                    jsonObject2.put("FNumber",jsonOne.getString("name"));    //物料编码



                    if(jsonArray2.size()>1){
                        jsonObject5.put("FNumber",jsonArray2.getString(1));      //仓位编号
                        String cwh = kingCangMapper.getCwCan(jsonArray2.getString(0));
                        jsonObject6.put("FSTOCKLOCID__"+cwh,jsonObject5);
                    }
                    jsonObject4.put("FNumber",jsonArray2.getString(0));      //仓库编号
                    jsonObject7.put("FNumber",kingCangMapper.getWuUnit(jsonOne.getString("name"),kingBdOrganizationMapper.fCodeToId(jsonOrgan.getString(0))));       //入库单位
                    jsonObject12.put("FNumber",kingCangMapper.getWuUnit(jsonOne.getString("name"),kingBdOrganizationMapper.fCodeToId(jsonOrgan.getString(0))));       //入库单位
                    jsonObject8.put("FNumber", "KCZT098");   //默认库存等级

                    jsonObject11.put("FNumber",jsonOrgan.getString(0));       //组织机构编码

                    // jsonObject12.put("FNumber",jsonObject.getString("organCode"));
                    jsonObject13.put("FNumber",jsonOne.getString("pi"));
                    jsonObject14.put("FNumber",jsonOrgan.getString(0));       //组织机构编码

                    jsonObject0.put("FMaterialId",jsonObject2);
                    jsonObject0.put("FSTOCKID",jsonObject4);
                    if(jsonArray2.size()>1) {
                        jsonObject0.put("FStockLocId", jsonObject6);
                    }
                    jsonObject0.put("FLot",jsonObject13);
                    jsonObject0.put("FStockStatusId",jsonObject8);
                    if(StringUtils.isNotBlank(kuCunParm.getfStatus())) {
                        jsonObject9.put("FNumber", kuCunParm.getfStatus());      //形态代码
                        jsonObject10.put("FAUXPROPID__FF100001", jsonObject9);
                        jsonObject0.put("FAuxPropId", jsonObject10);
                    }
                    if(jsonOne.containsKey("numberOne")){
                        if(jsonOne.getString("numberOne")!=null){
                            double jSum = Double.valueOf(jsonOne.getString("numberOne"));
                            jsonObject0.put("FExtAuxUnitQty",jSum);     //辅助入库数量
                        }
                    }
                    if(StringUtils.isNotBlank(kuCunParm.getfDanWei())){
                        jsonObject3.put("FNumber",kuCunParm.getfDanWei());     //辅助单位
                        jsonObject0.put("FExtAuxUnitId",jsonObject3);
                    }

                    if(kuCunParm.getfNum()!=null) {
                        jsonObject0.put("F_YMJT_Decimal", kuCunParm.getfNum().setScale(1).toString());           //转换率
                    }
                    double jSum2 = Double.valueOf(jsonOne.getString("number"));
                    jsonObject0.put("FQty",jSum2);                    //入库数量
                    jsonObject0.put("FUnitID",jsonObject7);
                    if(StringUtils.isNotBlank(kuCunParm.getfDateFirst())) {
                        jsonObject0.put("FProduceDate", DateUtil.formatDateTime(DateUtil.parse(kuCunParm.getfDateFirst())));
                    }
                    jsonObject0.put("FBaseUnitId",jsonObject12);
                    if(StringUtils.isNotBlank(kuCunParm.getfOwnId())) {
                        jsonObject0.put("FOWNERTYPEID", kuCunParm.getfOwnId());
                    }
                    if(StringUtils.isNotBlank(kuCunParm.getfKeepId())) {
                        jsonObject0.put("FKEEPERTYPEID", kuCunParm.getfKeepId());
                    }
                    jsonObject0.put("FKEEPERID",jsonObject11);
                    jsonObject0.put("FDistribution",false);
                    jsonObject0.put("FOWNERID",jsonObject14);
                    jsonObject0.put("F_YMJT_Qty2",1.0);           //转换率
                    jsonObject0.put("F_YMJT_Qty4",1.0);           //转换率
                    jsonObject0.put("F_YMJT_CheckBox2",false);
                    jsonObject0.put("F_YMJT_Text1",jsonObject.getString("mold"));          //单据类型
                    jsonObject0.put("F_YMJT_CheckBox3",false);
                    jsonArray.add(jsonObject0);
                }
            }
        }
        return jsonArray;
    }

    @Override
    public List<StkMiscKids> idToExamBillChildList(String fId){
        List<StkMiscKids> list = kingCangMapper.getExamBillChildOne(fId);
        if(list.size()>0){
            for(StkMiscKids stkMiscKids: list){
                if(StringUtils.isNotEmpty(kingBdWuMapper.fIdtoName(stkMiscKids.getfId()))){
                    stkMiscKids.setfName(kingBdWuMapper.fIdtoName(stkMiscKids.getfId()));
                }
            }
        }
        return list;
    }

    public List<ExamBill> idToExamBillList(KingCurrency kingCurrency){
        getKingCurr2(kingCurrency);
        List<ExamBill> list = kingCangMapper.getExamBillList(kingCurrency);
        if(list.size()>0){
            for(ExamBill examBill:list){
                if(examBill.getfType().equals("PUR_Requisition")){
                    List<StkMiscKids> list1 = idToExamBillChildList(kingCangMapper.PurCodetoId("T_"+examBill.getfType(),examBill.getfCode()));
                    if(list1.size()>0){
                        examBill.setfEntey(list1);
                    }
                }
                if(examBill.getfType().equals("STK_MISCELLANEOUS")){
                    List<StkMiscKids> list2 = idToStkmisChildList(kingCangMapper.PurCodetoId("T_"+examBill.getfType(),examBill.getfCode()));
                    if(list2.size()>0){
                        examBill.setfEntey(list2);
                    }
                }
            }
        }
        return list;
    }

    public List<ExamBill> idToExamBillApprovedList(KingCurrency kingCurrency){
        getKingCurr2(kingCurrency);
        List<ExamBill> list = kingCangMapper.getExamBillApprovedList(kingCurrency);
        if(list.size()>0){
            for(ExamBill examBill:list){
                if(examBill.getfType().equals("PUR_Requisition")){
                    List<StkMiscKids> list1 = idToExamBillChildList(kingCangMapper.PurCodetoId("T_"+examBill.getfType(),examBill.getfCode()));
                    if(list1.size()>0){
                        examBill.setfEntey(list1);
                    }
                }
                if(examBill.getfType().equals("STK_MISCELLANEOUS")){
                    List<StkMiscKids> list2 = idToStkmisChildList(kingCangMapper.PurCodetoId("T_"+examBill.getfType(),examBill.getfCode()));
                    if(list2.size()>0){
                        examBill.setfEntey(list2);
                    }
                }
            }
        }
        return list;
    }

    public List<ExamBill> idToExamBillLaunchList(KingCurrency kingCurrency){
        getKingCurr2(kingCurrency);
        List<ExamBill> list = kingCangMapper.getExamBillLaunchList2(kingCurrency);
        if(list.size()>0){
            for(ExamBill examBill:list){
                if(examBill.getfType().equals("PUR_Requisition")){
                    List<StkMiscKids> list1 = idToExamBillChildList(kingCangMapper.PurCodetoId("T_"+examBill.getfType(),examBill.getfCode()));
                    if(list1.size()>0){
                        examBill.setfEntey(list1);
                    }
                }
                if(examBill.getfType().equals("STK_MISCELLANEOUS")){
                    List<StkMiscKids> list2 = idToStkmisChildList(kingCangMapper.PurCodetoId("T_"+examBill.getfType(),examBill.getfCode()));
                    if(list2.size()>0){
                        examBill.setfEntey(list2);
                    }
                }
            }
        }
        return list;
    }

    public void getKingCurr(KingCurrency kingCurrency){
        if(kingCurrency.getMaplist()!=null){
            List<Map<String, Object>> list = kingCurrency.getMaplist();
            if(list.size()>0){
                for(Map<String, Object> map :list){
                    if(map.containsKey("type")){
                        if(map.get("type").toString().equals("1")){
                            kingCurrency.setStr3(map.get("identity").toString());
                        }
                        if(map.get("type").toString().equals("2")){
                            kingCurrency.setStr4(map.get("identity").toString());
                        }
                    }
                }
            }
        }
    }

    public void getKingCurr2(KingCurrency kingCurrency){
        if(kingCurrency.getMapl()!=null){
            Map<String, Object> list = kingCurrency.getMapl();
            if(list.containsKey("root")) {
                Map<String, Object> rootMap = (Map<String, Object>) list.get("root");
                if (rootMap.get("value").toString().equals("a")) {
                    Map<String, Object> dataMap = (Map<String, Object>) list.get("data");
                    kingCurrency.setStr3(dataMap.get("value").toString());
                }
                if (rootMap.get("value").toString().equals("b")) {
                    Map<String, Object> dataMap = (Map<String, Object>) list.get("data");
                    kingCurrency.setStr4(dataMap.get("value").toString());
                }
            }
        }
    }

    @Override
    public  List<Map<String, Object>> idToExamListALL(KingCurrency kingCurrency){
        List<Map<String, Object>>mapList = new LinkedList<>();
        List<ExamBill> oneList = idToExamBillList(kingCurrency);
        List<ExamBill> twoList = idToExamBillApprovedList(kingCurrency);
        List<ExamBill> threeList = idToExamBillLaunchList(kingCurrency);
        Map<String, Object> jsonOne = new LinkedHashMap<>();
        jsonOne.put("list",oneList);
        Map<String, Object> jsonTwo = new LinkedHashMap<>();
        jsonTwo.put("list",twoList);
        Map<String, Object> jsonThree = new LinkedHashMap<>();
        jsonThree.put("list",threeList);
        mapList.add(jsonOne);
        mapList.add(jsonTwo);
        mapList.add(jsonThree);
        return mapList;
    }

    @Override
    public String getExanParm(KingCurrency kingCurrency){
        Map<String, Object> mapList = new HashMap<>();
        mapList.put("FormId",kingCurrency.getStr1());
        List<String> list = new ArrayList<>();
        list.add(kingCurrency.getStr2());
        mapList.put("Numbers",list);
        mapList.put("UserId",kingCurrency.getStr3());
        mapList.put("ApprovalType",kingCurrency.getInt1());
//        Map<String, Object> mapList2 = new HashMap<>();
//        mapList2.put("data",mapList);
        return JSONObject.toJSONString(mapList);
    }

    @Override
    public  Map<String, Object> getExanBillTypeList(String userId){
        List<String> list = kingCangMapper.getExanBillType(userId);
        List<Map<String, String>> mapList = new ArrayList<>();
        if(list.size()>0){
            for(int i=0;i<list.size();i++){
                Map<String, String> map = new HashMap<>();
                map = kingTableNameMapper.codeToMap(list.get(i));
                mapList.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("data",mapList);
        map1.put("type",1);
        map1.put("value","a");
        map1.put("title","单据");
        Map<String, Object> map2 = new HashMap<>();
        List<Map<String, Object>> mapList2 = new ArrayList<>();
        Map<String, Object> mapOne = new HashMap<>();
        mapOne.put("text","日期降序");
        mapOne.put("value","DESC");
//        mapOne.put("status",false);
//        mapOne.put("type","2");
        Map<String, Object> mapTwo = new HashMap<>();
        mapTwo.put("text","日期升序");
        mapTwo.put("value","ESC");
//        mapTwo.put("status",false);
//        mapTwo.put("type","2");
        mapList2.add(mapOne);mapList2.add(mapTwo);
        map2.put("data",mapList2);
        map2.put("type",1);
        map2.put("value","b");
        map2.put("title","排序");
        List<Map<String, Object>> listMap = new ArrayList<>();
        listMap.add(map1);
        listMap.add(map2);
        Map<String, Object> listMap2 = new HashMap<>();
        listMap2.put("filterType",2);
        listMap2.put("data",listMap);

        return listMap2;
    }


    /**
     * 获取金蝶仓库
     */
    @Override
    public void getAllcode() throws Exception {
        List<String> list = kingCangMapper.getAllCang();
        if(list.size()>0) {
            for(int i=0;i<list.size();i++){
                if(iKingBdCangService.getNum(list.get(i))==0) {
                    Fanhui fanhui = getCan(list.get(i));
                    KingBdCang kingBdCang = new KingBdCang();
                    kingBdCang.setfId(String.valueOf(fanhui.getResult().getResult().getId()));
                    kingBdCang.setName(fanhui.getResult().getResult().getName().get(0).getValue());
                    kingBdCang.setfCode(fanhui.getResult().getResult().getNumber());
                    kingBdCang.setUserCode(fanhui.getResult().getResult().getUseOrgId().getNumber());
                    kingBdCang.setUserName(fanhui.getResult().getResult().getUseOrgId().getMultiLanguageText().get(0).getName());
                    if (fanhui.getResult().getResult().getStockFlexItem().size() > 0) {
                        if (fanhui.getResult().getResult().getStockFlexItem().get(0).getFlexId() != null) {
                            List<Fanhui.ResultBeanX.ResultBean.StockFlexItemBean.StockFlexDetailBean> list1 = fanhui.getResult().getResult().getStockFlexItem().get(0).getStockFlexDetail();
                            for (Fanhui.ResultBeanX.ResultBean.StockFlexItemBean.StockFlexDetailBean stockFlexDetailBean : list1) {
                                KingBdCangw kingBdCangw = new KingBdCangw();
                                kingBdCangw.setfCode(stockFlexDetailBean.getFlexEntryId().getNumber());
                                kingBdCangw.setfId(String.valueOf(stockFlexDetailBean.getId()));
                                kingBdCangw.setName(stockFlexDetailBean.getFlexEntryId().getName().get(0).getValue());
                                kingBdCangw.setsCode(kingBdCang.getfCode());
                                if (iKingBdCangwService.getNum(kingBdCangw.getfCode()) == 0) {
                                    iKingBdCangwService.insertKingBdCangw(kingBdCangw);
                                }
                            }
                        }
                    }
                    iKingBdCangService.insertKingBdCang(kingBdCang);
                }
            }
        }
    }

    @Override
    public void getWu() throws Exception {
        List<KingWu> list = kingCangMapper.getAllWu();
        if(list.size()>0){
            for(KingWu kingWu:list){
                KingBdWu kingBdWu = new KingBdWu();
                BeanUtils.copyProperties(kingWu,kingBdWu);
                if(iKingBdWuService.getNum(kingBdWu.getfId())==0){
                    kingBdWu.setfGroupCode(kingWu.getfClassCode());
                    kingBdWu.setfGroupName(kingWu.getfClassName());
                    KingBdWl kingBdWl = getBdwl(kingBdWu.getfId());
                    kingBdWu.setfUnit(kingBdWl.getResult().getResult().getMaterialBase().get(0).getBaseUnitId().getNumber());
                    if(kingBdWl.getResult().getResult().getMaterialStock().get(0)!=null) {
                        if (kingBdWl.getResult().getResult().getMaterialStock().get(0).getAuxUnitID() != null){
                            if (kingBdWl.getResult().getResult().getMaterialStock().get(0).getAuxUnitID().getNumber() != null) {
                                kingBdWu.setfAssis(kingBdWl.getResult().getResult().getMaterialStock().get(0).getAuxUnitID().getNumber());
                            }
                        }
                    }
                    iKingBdWuService.insertKingBdWu(kingBdWu);
                }
            }
        }
    }


    @Override
    public void getOrgan() throws Exception {
        List<String> list = kingBdWuMapper.getUserList();
        if(list.size()>0){
            for(int i=0;i<list.size();i++){
                if(iKingBdOrganizationService.getNum(list.get(i))==0){
                    KingBdOrganization kingBdOrganization = new KingBdOrganization();
                    Organ organ = getOrgan(list.get(i));
                    kingBdOrganization.setfId(list.get(i));
                    kingBdOrganization.setfCode(organ.getResult().getResult().getNumber());
                    kingBdOrganization.setfName(organ.getResult().getResult().getName().get(0).getValue());
                    iKingBdOrganizationService.insertKingBdOrganization(kingBdOrganization);
                    redisCache.deleteObject("Organ");
                    redisCache.setCacheList("Organ",iKingBdOrganizationService.getALL());
                }
            }
        }
    }

    public static Fanhui getCan(String ids) throws Exception {
        Fanhui fanhui = new Fanhui();
        if(org.apache.commons.lang3.StringUtils.isNotEmpty(ids)){
            org.json.JSONObject jsonObject2 = new org.json.JSONObject();
            jsonObject2.put("CreateOrgId",0);
            jsonObject2.put("Number","");
            jsonObject2.put("Id",ids);
            com.alibaba.fastjson.JSONObject object = InvokeHelper.Invoke2("View","BD_STOCK",jsonObject2.toString(),InvokeHelper.getCook());
            fanhui = JSON.toJavaObject(object,Fanhui.class);
        }
        return fanhui;
    }

    public static KingBdWl getBdwl(String ids) throws Exception {
        KingBdWl kingBdWl = new KingBdWl();
        if(org.apache.commons.lang3.StringUtils.isNotEmpty(ids)){
            org.json.JSONObject jsonObject2 = new org.json.JSONObject();
            jsonObject2.put("CreateOrgId",0);
            jsonObject2.put("Number","");
            jsonObject2.put("Id",ids);
            com.alibaba.fastjson.JSONObject object = InvokeHelper.Invoke2("View","BD_MATERIAL",jsonObject2.toString(),InvokeHelper.getCook());
            kingBdWl = JSON.toJavaObject(object,KingBdWl.class);
        }
        return kingBdWl;
    }

    public static Organ getOrgan(String ids) throws Exception {
        Organ organ = new Organ();
        if(org.apache.commons.lang3.StringUtils.isNotEmpty(ids)){
            org.json.JSONObject jsonObject2 = new org.json.JSONObject();
            jsonObject2.put("CreateOrgId",0);
            jsonObject2.put("Number","");
            jsonObject2.put("Id",ids);
            com.alibaba.fastjson.JSONObject object = InvokeHelper.Invoke2("View","ORG_Organizations",jsonObject2.toString(),InvokeHelper.getCook());
            organ = JSON.toJavaObject(object,Organ.class);
        }
        return organ;
    }

    @Override
    public List<Map<String, String>> getTransTypeList(String fId){
        return kingCangMapper.getTransTypeList(kingCangMapper.oranNumToId(fId));
    }

    @Override
    public List<Map<String, String>> getTransOrgan(){
        List<Map<String, String>> list = kingCangMapper.getTransOrgan();
        List<Map<String, String>> mapList = new ArrayList<>();
        if(list.size()>0){
            for(Map<String, String> map:list){
                Map<String, String> map1 = new HashMap<>();
                map1.put("laber",map.get("fCode"));
                map1.put("value",map.get("fName")+"("+map.get("fRemark")+")");
                mapList.add(map1);
            }
        }
        return mapList;
    }

    public String getObjectZhu4(JSONObject jsonObject){
        Map<String, Object> jsonObject1 = new LinkedHashMap();
        Map<String, Object> jsonObject2 = new LinkedHashMap();
        Map<String, String> jsonObject3 = new LinkedHashMap();
        Map<String, String> jsonObject4 = new LinkedHashMap();
        Map<String, String> jsonObject5 = new LinkedHashMap();
        Map<String, String> jsonObject6 = new LinkedHashMap();
        Map<String, String> jsonObject7 = new LinkedHashMap();
        Map<String, String> jsonObject8 = new LinkedHashMap();
        Map<String, String> jsonObject9 = new LinkedHashMap();
        Map<String, String> jsonObject10 = new LinkedHashMap();
        Map<String, String> jsonObject11 = new LinkedHashMap();
        Map<String, String> jsonObject12 = new LinkedHashMap();
        Map<String, String> jsonObject13 = new LinkedHashMap();
        Map<String, String> jsonObject14 = new LinkedHashMap();
        Map<String, String> jsonObject15 = new LinkedHashMap();
        Map<String, String> jsonObject16 = new LinkedHashMap();
        com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();
        jsonObject3.put("FNumber",jsonObject.getString("corgan")); //调出机构代啊
        jsonObject6.put("FNumber",jsonObject.getString("corgan")); //调出机构代啊
        jsonObject7.put("FNumber",jsonObject.getString("corgan")); //调出机构代啊
        jsonObject8.put("FNumber",jsonObject.getString("corgan")); //调出机构代啊
        jsonObject9.put("FNumber",jsonObject.getString("rorgan")); //调入机构代啊
        jsonObject10.put("FNumber","HLTX01_SYS"); //
        jsonObject11.put("FNumber",jsonObject.getString("rorgan")); //调入机构代啊
        jsonObject12.put("FNumber",jsonObject.getString("corgan")); //调出机构代啊
        jsonObject13.put("FNumber",jsonObject.getString("rorgan")); //调入机构代啊
        jsonObject14.put("FNumber","MR001"); //
        jsonObject15.put("FNumber",jsonObject.getString("yeType")); //调拨业务类型

        jsonObject4.put("FNumber","PRE001");   //本位币 人民币代码
        jsonObject16.put("FNumber","PRE001");   //本位币 人民币代码
        jsonObject5.put("FNUMBER","ZJDB01_SYS");   //直接调拨单代码

//        if(jsonObject.containsKey("fentity")) {
//            if (jsonObject.get("fentity") != null) {
//                jsonArray= jsonObject.getJSONArray("fentity");
//            }
//        }
       // double jSum = Double.valueOf(jsonArray.size());
        jsonObject2.put("FID",0);
        jsonObject2.put("FBillTypeID",jsonObject5);
        jsonObject2.put("FBizType","NORMAL");
        jsonObject2.put("FTransferDirect","GENERAL");  //组织机构
        jsonObject2.put("FTransferBizType",jsonObject.getString("mold")); //调拨单类型
        jsonObject2.put("FSettleOrgId",jsonObject3);
        jsonObject2.put("FSaleOrgId",jsonObject6);
        jsonObject2.put("FStockOutOrgId",jsonObject7);
        jsonObject2.put("FOwnerTypeOutIdHead","BD_OwnerOrg"); //调拨方向：普通
        jsonObject2.put("FOwnerOutIdHead",jsonObject8);
        jsonObject2.put("FStockOrgId",jsonObject9);
        jsonObject2.put("FIsIncludedTax",true);
        jsonObject2.put("FIsPriceExcludeTax",true);
        jsonObject2.put("FExchangeTypeId",jsonObject10);
        jsonObject2.put("FOwnerTypeIdHead","BD_OwnerOrg");
        jsonObject2.put("FSETTLECURRID",jsonObject4);
        jsonObject2.put("FExchangeRate","1.0");
        jsonObject2.put("FOwnerIdHead",jsonObject11);
        jsonObject2.put("FDate", DateUtil.formatDateTime(DateUtil.parse(jsonObject.getString("current"))));
        jsonObject2.put("FBaseCurrId",jsonObject16);
        jsonObject2.put("FSUPPLIERID",jsonObject12);
        jsonObject2.put("FCustID",jsonObject13);
        jsonObject2.put("F_YMJT_Assistant",jsonObject14);
        jsonObject2.put("F_YMJT_CheckBox",false);
        jsonObject2.put("F_YMJT_Qty","1.0");
        jsonObject2.put("F_YMJT_Qty2","1.0");
        jsonObject2.put("F_YMJT_Qty21","1.0");
        jsonObject2.put("F_YMJT_CheckBox1",false);
        jsonObject2.put("F_YMJT_CheckBox11",false);
        jsonObject2.put("F_YMJT_Base5",jsonObject15);
        jsonObject2.put("F_YMJT_Datetime1",DateUtil.formatDateTime(DateUtil.parse(jsonObject.getString("current"))));

        List<Map<String, Object>> jsonArray1 = getObjectWuList4Two(jsonObject);
        if(jsonArray1==null){
            return "null";
        }
        jsonObject2.put("FBillEntry",jsonArray1);
        jsonObject1.put("Model",jsonObject2);
        String x =JSONObject.toJSONString(jsonObject1);
        return x;
    }

    public List<Map<String, Object>> getObjectWuList4(JSONObject jsonObject){
        //com.alibaba.fastjson.JSONArray jsonOrgan = jsonObject.getJSONArray("organ");
        List<Map<String, Object>> jsonArray = new ArrayList<>();
        if(jsonObject.containsKey("fentity")){
            if(jsonObject.get("fentity")!=null){
                com.alibaba.fastjson.JSONArray ja = jsonObject.getJSONArray("fentity");
                for(int i=0;i<ja.size();i++) {
                    ArrayList sja = (ArrayList) ja.get(i);
                    JSONObject jsonOne = (JSONObject) JSON.toJSON(sja.get(0));
                    Map jsonObject0 = new LinkedHashMap();
                    Map<String, String> jsonObject1 = new LinkedHashMap();
                    Map<String, String> jsonObject2 =new LinkedHashMap();
                    Map<String, String> jsonObject3 = new LinkedHashMap();
                    Map<String, String> jsonObject4 = new LinkedHashMap();
                    Map<String, String> jsonObject5 = new LinkedHashMap();
                    Map<String, Object> jsonObject6 = new LinkedHashMap();
                    Map<String, String> jsonObject7 = new LinkedHashMap();
                    Map<String, String> jsonObject8 = new LinkedHashMap();
                    Map<String, String> jsonObject9 = new LinkedHashMap();
                    Map<String, Object> jsonObject10 = new LinkedHashMap();
                    //Map<String, String> jsonObject11 = new LinkedHashMap();
                    Map<String, String> jsonObject12 = new LinkedHashMap();
                    Map<String, String> jsonObject13 = new LinkedHashMap();
                    //Map<String, String> jsonObject14 = new LinkedHashMap();
                    Map<String, String> jsonObject15 = new LinkedHashMap();
                    Map<String, Object> jsonObject16 = new LinkedHashMap();
                    Map<String, Object> jsonObject17 = new LinkedHashMap();
                    Map<String, Object> jsonObject18 = new LinkedHashMap();
                    Map<String, Object> jsonObject19 = new LinkedHashMap();
                    Map<String, Object> jsonObject20 = new LinkedHashMap();
                    Map<String, Object> jsonObject21 = new LinkedHashMap();
                    Map<String, Object> jsonObject22 = new LinkedHashMap();
                    Map<String, Object> jsonObject23 = new LinkedHashMap();
                    Map<String, Object> jsonObject24 = new LinkedHashMap();
                    Map<String, Object> jsonObject25 = new LinkedHashMap();
                    Map<String, Object> jsonObject26 = new LinkedHashMap();



                    com.alibaba.fastjson.JSONArray jsonArray1 = jsonOne.getJSONArray("name");
                    com.alibaba.fastjson.JSONArray jsonArray2 = jsonOne.getJSONArray("can");
                    com.alibaba.fastjson.JSONArray jsonArray3 = jsonOne.getJSONArray("rcan");
                    FloatNumber floatNumber = new FloatNumber();
                    floatNumber.setfId(kingBdOrganizationMapper.fCodeToId(jsonObject.getString("corgan")));
                    floatNumber.setcPCode(jsonArray1.getString(jsonArray1.size()-1));
                    if(jsonArray2.size()>1){
                        String Canshu = kingCangMapper.getCwCan(jsonArray2.getString(1));
                        floatNumber.setfCangWei(kingCangMapper.getCwFid(Canshu,jsonArray2.getString(1)));
//                       floatNumber.setfCangWei(kingBdCangwMapper.fCodeToId(jsonArray2.getString(1)));      //仓位编号
                    }else {
                        floatNumber.setfCang(jsonArray2.getString(0));
                    }
                    floatNumber.setfPi(jsonOne.getString("pi"));
                    KuCunParm kuCunParm = kingCangMapper.getKucunFu(floatNumber);
                    if(kuCunParm==null){
                        return jsonArray;
                    }



                    jsonObject1.put("FNUMBER",jsonArray1.getString(jsonArray1.size()-1));   //物料编码
                    jsonObject2.put("FNumber",jsonArray1.getString(jsonArray1.size()-1));    //物料编码
                    jsonObject3.put("FNumber",kuCunParm.getfDanWei());     //辅助单位


                    if(jsonArray2.size()>1){
                        jsonObject5.put("FNumber",jsonArray2.getString(1));      //仓位编号
                        String cwh = kingCangMapper.getCwCan(jsonArray2.getString(0));
                        jsonObject6.put("FSRCSTOCKLOCID__"+cwh,jsonObject5);
                    }
                    if(jsonArray3.size()>1){
                        jsonObject15.put("FNumber",jsonArray3.getString(1));      //仓位编号
                        String cwh = kingCangMapper.getCwCan(jsonArray3.getString(0));
                        jsonObject16.put("FDESTSTOCKLOCID__"+cwh,jsonObject15);
                    }
                    jsonObject17.put("FNumber",jsonArray3.getString(0));      //仓库编号
                    jsonObject4.put("FNumber",jsonArray2.getString(0));      //仓库编号
                    jsonObject7.put("FNumber",kingCangMapper.getWuUnit(jsonArray1.getString(jsonArray1.size()-1),kingBdOrganizationMapper.fCodeToId(jsonObject.getString("corgan"))));       //入库单位
                    jsonObject12.put("FNumber",kingCangMapper.getWuUnit(jsonArray1.getString(jsonArray1.size()-1),kingBdOrganizationMapper.fCodeToId(jsonObject.getString("corgan"))));       //入库单位
                    jsonObject26.put("FNumber",kingCangMapper.getWuUnit(jsonArray1.getString(jsonArray1.size()-1),kingBdOrganizationMapper.fCodeToId(jsonObject.getString("corgan"))));       //入库单位
                    jsonObject8.put("FNumber", "KCZT098");   //默认库存等级
                    jsonObject25.put("FNumber", "KCZT098");   //默认库存等级
                    if(StringUtils.isNotBlank(kuCunParm.getfStatus())) {
                        jsonObject9.put("FNumber", kuCunParm.getfStatus());      //形态代码
                        jsonObject10.put("FAUXPROPID__FF100001", jsonObject9);
                    }

                    jsonObject0.put("FMaterialId",jsonObject2);
                    if(jsonOne.containsKey("numberOne")){
                        if(jsonOne.getString("numberOne")!=null){
                            double jSum = Double.valueOf(jsonOne.getString("numberOne"));
                            jsonObject0.put("FExtAuxUnitQty",jSum);     //辅助入库数量
                            jsonObject0.put("FSecQty",jSum);
                            jsonObject0.put("FExtAuxUnitId",jsonObject3);
                        }
                    }
                    jsonObject0.put("F_YMJT_Integer",1);
                    double jSum2 = Double.valueOf(jsonOne.getString("number"));
                    jsonObject0.put("FUnitID",jsonObject7);
                    jsonObject0.put("FQty",jSum2);
                    jsonObject0.put("FBaseQty",jSum2);
                    jsonObject0.put("FPriceUnitID",jsonObject12);
                    jsonObject0.put("FPriceQty",jSum2);
                    jsonObject0.put("FPriceBaseQty",jSum2);
                    jsonObject0.put("FOwnerTypeOutId","BD_OwnerOrg");
                    jsonObject0.put("FOwnerOutId",jsonObject.getString("corgam"));
                    jsonObject0.put("FSrcStockId",jsonObject4);
                    if(jsonArray2.size()>1) {
                        jsonObject0.put("FSrcStockLocId", jsonObject6);
                    }
                    jsonObject0.put("FSrcStockStatusId",jsonObject8);
                    if(jsonOne.containsKey("pi")){
                        if(StringUtils.isNotBlank(jsonOne.getString("pi"))){
                            jsonObject13.put("FNumber",jsonOne.getString("pi"));
                            jsonObject0.put("FLot",jsonObject13);
                        }
                    }
                    if(StringUtils.isNotBlank(kuCunParm.getfStatus())) {
                        jsonObject0.put("FAuxPropId", jsonObject10);
                    }
                    jsonObject0.put("FProduceDate",DateUtil.formatDateTime(DateUtil.parse(kuCunParm.getfDateFirst())));
                    jsonObject0.put("FExpiryDate",DateUtil.formatDateTime(DateUtil.parse(kuCunParm.getfDateEnd())));
                    jsonObject0.put("FBusinessDate",DateUtil.formatDateTime(DateUtil.parse(jsonObject.getString("current"))));
                    jsonObject0.put("FOwnerTypeId","BD_OwnerOrg");

                    jsonObject20.put("FNumber",jsonObject.getString("rorgan"));
                    jsonObject0.put("FOwnerId",jsonObject20);

                    jsonObject0.put("FDestStockId",jsonObject17);
                    if(jsonArray2.size()>1) {
                        jsonObject0.put("FDestStockLocId", jsonObject16);
                    }
                    if(jsonOne.containsKey("pi")){
                        if(StringUtils.isNotBlank(jsonOne.getString("pi"))){
                            jsonObject18.put("FNumber",jsonOne.getString("pi"));
                            jsonObject0.put("FDestLot",jsonObject18);
                        }
                    }

                    jsonObject0.put("FDestStockStatusId",jsonObject25);
                    if(StringUtils.isNotBlank(kuCunParm.getfDanWei())){
                        jsonObject19.put("FNumber",kuCunParm.getfDanWei());
                        jsonObject0.put("FSecUnitId",jsonObject19);
                    }
                    jsonObject0.put("FBaseUnitId",jsonObject26);
                    jsonObject0.put("FISFREE",false);
                    jsonObject0.put("FKeeperTypeId","BD_KeeperOrg");

                    jsonObject21.put("FNumber",jsonObject.getString("rorgan"));
                    jsonObject0.put("FKeeperId",jsonObject21);
                    jsonObject0.put("FKeeperTypeOutId","BD_KeeperOrg");

                    jsonObject22.put("FNumber",jsonObject.getString("corgan"));
                    jsonObject0.put("FKeeperOutId",jsonObject22);

                    jsonObject23.put("FNumber",jsonArray1.getString(jsonArray1.size()-1));
                    jsonObject0.put("FDestMaterialId",jsonObject23);

                    jsonObject24.put("FNumber",kingCangMapper.getWuUnit(jsonArray1.getString(jsonArray1.size()-1),kingBdOrganizationMapper.fCodeToId(jsonObject.getString("corgan"))));
                    jsonObject0.put("FSaleUnitId",jsonObject24);
                    jsonObject0.put("FSaleQty",jSum2);
                    jsonObject0.put("FSalBaseQty",jSum2);
                    jsonObject0.put("FTransReserveLink",false);
                    jsonObject0.put("FCheckDelivery",false);
                    jsonObject0.put("F_YMJT_Qty1","1.0");
                    jsonObject0.put("F_YMJT_Qty3","1.0");
                    jsonObject0.put("F_YMJT_Qty4","1.0");
                    jsonObject0.put("F_YMJT_Text","1");
                    jsonObject0.put("F_YMJT_CheckBox2",false);


                    jsonArray.add(jsonObject0);
                }
            }
        }
        return jsonArray;
    }

    public List<Map<String, Object>> getObjectWuList4Two(JSONObject jsonObject){
        //com.alibaba.fastjson.JSONArray jsonOrgan = jsonObject.getJSONArray("organ");
        List<Map<String, Object>> jsonArray = new ArrayList<>();
        if(jsonObject.containsKey("fentity")){
            if(jsonObject.get("fentity")!=null){
                com.alibaba.fastjson.JSONArray ja = jsonObject.getJSONArray("fentity");
                for(int i=0;i<ja.size();i++) {
                    ArrayList sja = (ArrayList) ja.get(i);
                    JSONObject jsonOne = (JSONObject) JSON.toJSON(sja.get(0));
                    Map jsonObject0 = new LinkedHashMap();
                    Map<String, String> jsonObject1 = new LinkedHashMap();
                    Map<String, String> jsonObject2 =new LinkedHashMap();
                    Map<String, String> jsonObject3 = new LinkedHashMap();
                    Map<String, String> jsonObject4 = new LinkedHashMap();
                    Map<String, String> jsonObject5 = new LinkedHashMap();
                    Map<String, Object> jsonObject6 = new LinkedHashMap();
                    Map<String, String> jsonObject7 = new LinkedHashMap();
                    Map<String, String> jsonObject8 = new LinkedHashMap();
                    Map<String, String> jsonObject9 = new LinkedHashMap();
                    Map<String, Object> jsonObject10 = new LinkedHashMap();
                    //Map<String, String> jsonObject11 = new LinkedHashMap();
                    Map<String, String> jsonObject12 = new LinkedHashMap();
                    Map<String, String> jsonObject13 = new LinkedHashMap();
                    //Map<String, String> jsonObject14 = new LinkedHashMap();
                    Map<String, String> jsonObject15 = new LinkedHashMap();
                    Map<String, Object> jsonObject16 = new LinkedHashMap();
                    Map<String, Object> jsonObject17 = new LinkedHashMap();
                    Map<String, Object> jsonObject18 = new LinkedHashMap();
                    Map<String, Object> jsonObject19 = new LinkedHashMap();
                    Map<String, Object> jsonObject20 = new LinkedHashMap();
                    Map<String, Object> jsonObject21 = new LinkedHashMap();
                    Map<String, Object> jsonObject22 = new LinkedHashMap();
                    Map<String, Object> jsonObject23 = new LinkedHashMap();
                    Map<String, Object> jsonObject24 = new LinkedHashMap();
                    Map<String, Object> jsonObject25 = new LinkedHashMap();
                    Map<String, Object> jsonObject26 = new LinkedHashMap();



                    //com.alibaba.fastjson.JSONArray jsonArray1 = jsonOne.getJSONArray("name");
                    com.alibaba.fastjson.JSONArray jsonArray2 = jsonOne.getJSONArray("can");
                    com.alibaba.fastjson.JSONArray jsonArray3 = jsonOne.getJSONArray("rcan");
                    FloatNumber floatNumber = new FloatNumber();
                    floatNumber.setfId(kingBdOrganizationMapper.fCodeToId(jsonObject.getString("corgan")));
                    floatNumber.setcPCode(jsonOne.getString("name"));
                    if(jsonArray2.size()>1){
                        String Canshu = kingCangMapper.getCwCan(jsonArray2.getString(1));
                        floatNumber.setfCangWei(kingCangMapper.getCwFid(Canshu,jsonArray2.getString(1)));
//                       floatNumber.setfCangWei(kingBdCangwMapper.fCodeToId(jsonArray2.getString(1)));      //仓位编号
                    }else {
                        floatNumber.setfCang(jsonArray2.getString(0));
                    }
                    floatNumber.setfPi(jsonOne.getString("pi"));
                    KuCunParm kuCunParm = kingCangMapper.getKucunFu(floatNumber);
                    if(kuCunParm==null){
                        return jsonArray;
                    }



                    jsonObject1.put("FNUMBER",jsonOne.getString("name"));   //物料编码
                    jsonObject2.put("FNumber",jsonOne.getString("name"));    //物料编码
                    jsonObject3.put("FNumber",kuCunParm.getfDanWei());     //辅助单位


                    if(jsonArray2.size()>1){
                        jsonObject5.put("FNumber",jsonArray2.getString(1));      //仓位编号
                        String cwh = kingCangMapper.getCwCan(jsonArray2.getString(0));
                        jsonObject6.put("FSRCSTOCKLOCID__"+cwh,jsonObject5);
                    }
                    if(jsonArray3.size()>1){
                        jsonObject15.put("FNumber",jsonArray3.getString(1));      //仓位编号
                        String cwh = kingCangMapper.getCwCan(jsonArray3.getString(0));
                        jsonObject16.put("FDESTSTOCKLOCID__"+cwh,jsonObject15);
                    }
                    jsonObject17.put("FNumber",jsonArray3.getString(0));      //仓库编号
                    jsonObject4.put("FNumber",jsonArray2.getString(0));      //仓库编号
                    jsonObject7.put("FNumber",kingCangMapper.getWuUnit(jsonOne.getString("name"),kingBdOrganizationMapper.fCodeToId(jsonObject.getString("corgan"))));       //入库单位
                    jsonObject12.put("FNumber",kingCangMapper.getWuUnit(jsonOne.getString("name"),kingBdOrganizationMapper.fCodeToId(jsonObject.getString("corgan"))));       //入库单位
                    jsonObject26.put("FNumber",kingCangMapper.getWuUnit(jsonOne.getString("name"),kingBdOrganizationMapper.fCodeToId(jsonObject.getString("corgan"))));       //入库单位
                    jsonObject8.put("FNumber", "KCZT098");   //默认库存等级
                    jsonObject25.put("FNumber", "KCZT098");   //默认库存等级
                    if(StringUtils.isNotBlank(kuCunParm.getfStatus())) {
                        jsonObject9.put("FNumber", kuCunParm.getfStatus());      //形态代码
                        jsonObject10.put("FAUXPROPID__FF100001", jsonObject9);
                    }

                    jsonObject0.put("FMaterialId",jsonObject2);
                    if(jsonOne.containsKey("numberOne")){
                        if(jsonOne.getString("numberOne")!=null){
                            double jSum = Double.valueOf(jsonOne.getString("numberOne"));
                            jsonObject0.put("FExtAuxUnitQty",jSum);     //辅助入库数量
                            jsonObject0.put("FSecQty",jSum);
                            jsonObject0.put("FExtAuxUnitId",jsonObject3);
                        }
                    }
                    jsonObject0.put("F_YMJT_Integer",1);
                    double jSum2 = Double.valueOf(jsonOne.getString("number"));
                    jsonObject0.put("FUnitID",jsonObject7);
                    jsonObject0.put("FQty",jSum2);
                    jsonObject0.put("FBaseQty",jSum2);
                    jsonObject0.put("FPriceUnitID",jsonObject12);
                    jsonObject0.put("FPriceQty",jSum2);
                    jsonObject0.put("FPriceBaseQty",jSum2);
                    jsonObject0.put("FOwnerTypeOutId","BD_OwnerOrg");
                    jsonObject0.put("FOwnerOutId",jsonObject.getString("corgam"));
                    jsonObject0.put("FSrcStockId",jsonObject4);
                    if(jsonArray2.size()>1) {
                        jsonObject0.put("FSrcStockLocId", jsonObject6);
                    }
                    jsonObject0.put("FSrcStockStatusId",jsonObject8);
                    if(jsonOne.containsKey("pi")){
                        if(StringUtils.isNotBlank(jsonOne.getString("pi"))){
                            jsonObject13.put("FNumber",jsonOne.getString("pi"));
                            jsonObject0.put("FLot",jsonObject13);
                        }
                    }
                    if(StringUtils.isNotBlank(kuCunParm.getfStatus())) {
                        jsonObject0.put("FAuxPropId", jsonObject10);
                    }
                    jsonObject0.put("FProduceDate",DateUtil.formatDateTime(DateUtil.parse(kuCunParm.getfDateFirst())));
                    jsonObject0.put("FExpiryDate",DateUtil.formatDateTime(DateUtil.parse(kuCunParm.getfDateEnd())));
                    jsonObject0.put("FBusinessDate",DateUtil.formatDateTime(DateUtil.parse(jsonObject.getString("current"))));
                    jsonObject0.put("FOwnerTypeId","BD_OwnerOrg");

                    jsonObject20.put("FNumber",jsonObject.getString("rorgan"));
                    jsonObject0.put("FOwnerId",jsonObject20);

                    jsonObject0.put("FDestStockId",jsonObject17);
                    if(jsonArray2.size()>1) {
                        jsonObject0.put("FDestStockLocId", jsonObject16);
                    }
                    if(jsonOne.containsKey("pi")){
                        if(StringUtils.isNotBlank(jsonOne.getString("pi"))){
                            jsonObject18.put("FNumber",jsonOne.getString("pi"));
                            jsonObject0.put("FDestLot",jsonObject18);
                        }
                    }

                    jsonObject0.put("FDestStockStatusId",jsonObject25);
                    if(StringUtils.isNotBlank(kuCunParm.getfDanWei())){
                        jsonObject19.put("FNumber",kuCunParm.getfDanWei());
                        jsonObject0.put("FSecUnitId",jsonObject19);
                    }
                    jsonObject0.put("FBaseUnitId",jsonObject26);
                    jsonObject0.put("FISFREE",false);
                    jsonObject0.put("FKeeperTypeId","BD_KeeperOrg");

                    jsonObject21.put("FNumber",jsonObject.getString("rorgan"));
                    jsonObject0.put("FKeeperId",jsonObject21);
                    jsonObject0.put("FKeeperTypeOutId","BD_KeeperOrg");

                    jsonObject22.put("FNumber",jsonObject.getString("corgan"));
                    jsonObject0.put("FKeeperOutId",jsonObject22);

                    jsonObject23.put("FNumber",jsonOne.getString("name"));
                    jsonObject0.put("FDestMaterialId",jsonObject23);

                    jsonObject24.put("FNumber",kingCangMapper.getWuUnit(jsonOne.getString("name"),kingBdOrganizationMapper.fCodeToId(jsonObject.getString("corgan"))));
                    jsonObject0.put("FSaleUnitId",jsonObject24);
                    jsonObject0.put("FSaleQty",jSum2);
                    jsonObject0.put("FSalBaseQty",jSum2);
                    jsonObject0.put("FTransReserveLink",false);
                    jsonObject0.put("FCheckDelivery",false);
                    jsonObject0.put("F_YMJT_Qty1","1.0");
                    jsonObject0.put("F_YMJT_Qty3","1.0");
                    jsonObject0.put("F_YMJT_Qty4","1.0");
                    jsonObject0.put("F_YMJT_Text","1");
                    jsonObject0.put("F_YMJT_CheckBox2",false);


                    jsonArray.add(jsonObject0);
                }
            }
        }
        return jsonArray;
    }

    @Override
    public String getTransParam(JSONObject jsonObject){
        String x  = getObjectZhu4(jsonObject);
        return x;
    }

    @Override
    public List<Map<String, Object>> getTransRuArry(String fId){
        List<StkMisc> list = kingCangMapper.useridToSTKTransList(fId);
        List<KingZjRk> list1 = new ArrayList<>();
        if(list.size()>0){
            for(StkMisc stkMisc:list){
                KingZjRk kingZjRk = new KingZjRk();
                BeanUtils.copyProperties(stkMisc,kingZjRk);
                if(StringUtils.isNotBlank(kingZjRk.getcOrgan())) {
                    kingZjRk.setcName(kingCangMapper.organIdtoName(kingZjRk.getcOrgan()));
                }
                if(StringUtils.isNotBlank(kingZjRk.getrOrgan())) {
                    kingZjRk.setrName(kingCangMapper.organIdtoName(kingZjRk.getrOrgan()));
                }
                kingZjRk.setfWuliao(idToStkmisTransChildList(stkMisc.getfId()));
                list1.add(kingZjRk);
            }
        }
        List<Map<String, Object>>mapList = new LinkedList<>();
        if(list1.size()>0){
            List<KingZjRk> listOne = new ArrayList<>();
            List<KingZjRk> listTwo = new ArrayList<>();
            List<KingZjRk> listThree = new ArrayList<>();
            for(KingZjRk kingZjRk :list1){
                if(kingZjRk.getfState().equals("B")){
                    kingZjRk.setFlag1(false);
                    kingZjRk.setFlag2(true);
                    kingZjRk.setFlag3(false);
                    listTwo.add(kingZjRk);
                }else if (kingZjRk.getfState().equals("C")){
                    kingZjRk.setFlag1(false);
                    kingZjRk.setFlag2(false);
                    kingZjRk.setFlag3(true);
                    listThree.add(kingZjRk);
                }else {
                    kingZjRk.setFlag1(true);
                    kingZjRk.setFlag2(false);
                    kingZjRk.setFlag3(false);
                    listOne.add(kingZjRk);
                }
            }
            Map<String, Object> jsonOne = new LinkedHashMap<>();
            jsonOne.put("list",listOne);
            Map<String, Object> jsonTwo = new LinkedHashMap<>();
            jsonTwo.put("list",listTwo);
            Map<String, Object> jsonThree = new LinkedHashMap<>();
            jsonThree.put("list",listThree);
            mapList.add(jsonOne);
            mapList.add(jsonTwo);
            mapList.add(jsonThree);
        }
        return mapList;
    }

    public List<StkMiscKids> idToStkmisTransChildList(String fId){
        List<StkMiscKids> list = kingCangMapper.idToSTKTransChild(fId);
        if(list.size()>0){
            for(StkMiscKids stkMiscKids: list){
                if(StringUtils.isNotEmpty(kingBdWuMapper.fIdtoName(stkMiscKids.getfId()))){
                    stkMiscKids.setfName(kingBdWuMapper.fIdtoName(stkMiscKids.getfId()));
                }
                if(StringUtils.isNotEmpty(kingBdCangMapper.fIdtoName(stkMiscKids.getfCangId()))){
                    stkMiscKids.setfCangName(kingBdCangMapper.fIdtoName(stkMiscKids.getfCangId()));
                }
                if(StringUtils.isNotEmpty(kingBdCangwMapper.fIdtoName(stkMiscKids.getfWeiId()))){
                    stkMiscKids.setfWeiName(kingBdCangwMapper.fIdtoName(stkMiscKids.getfWeiId()));
                }
                if(StringUtils.isNotEmpty(kingBdCangMapper.fIdtoName(stkMiscKids.getfCangId2()))){
                    stkMiscKids.setfCangName2(kingBdCangMapper.fIdtoName(stkMiscKids.getfCangId2()));
                }
                if(StringUtils.isNotEmpty(kingBdCangwMapper.fIdtoName(stkMiscKids.getfWeiId2()))){
                    stkMiscKids.setfWeiName2(kingBdCangwMapper.fIdtoName(stkMiscKids.getfWeiId2()));
                }
            }
        }
        return list;
    }

    @Override
    public Map<String, String> getAppVersion(String fId){
        KingAppVersion kingAppVersion = kingAppVersionMapper.getAppVersion();
        Map<String, String> map = new HashMap<>();
        if(fId.equals(kingAppVersion.getVersion())){
            map.put("flag","true");
        }else{
            map.put("flag","false");
            map.put("url",kingAppVersion.getUrl());
        }
        return map;
    }

    @Override
    public List<Map<String, String>> getWuliao(String fId){
        List<Map<String, String>> list = kingCangMapper.getWuliao(fId);
        List<Map<String, String>> list1 = new ArrayList<>();
        for(Map<String, String> map:list){
            Map<String, String> mapOne = new HashMap();
            if(map.containsKey("id")){
                mapOne.put("id",map.get("id"));
            }
            if(StringUtils.isNotBlank(map.get("remark").toString())){
                mapOne.put("name","["+map.get("id")+"]"+map.get("name")+"("+map.get("remark")+")");
            }else {
                mapOne.put("name","["+map.get("id")+"]"+map.get("name"));
            }
            list1.add(mapOne);
        }
        return list1;
    }

    @Override
    public List<Map<String, String>> getKuCunWuliao(String fId){
        List<Map<String, String>> list = kingCangMapper.getKuCunWuliao(fId);
        List<Map<String, String>> list1 = new ArrayList<>();
        for(Map<String, String> map:list){
            Map<String, String> mapOne = new HashMap();
            if(map.containsKey("id")){
                mapOne.put("id",map.get("id"));
            }
            if(StringUtils.isNotBlank(map.get("remark").toString())){
                mapOne.put("name","["+map.get("id")+"]"+map.get("name")+"("+map.get("remark")+")");
            }else {
                mapOne.put("name","["+map.get("id")+"]"+map.get("name"));
            }
            list1.add(mapOne);
        }
        return list1;
    }

    @Override
    public Integer getExamNum(String fId){
        return kingCangMapper.getExamNum(fId);
    }

    @Override
    public void delRedisKey(){
        List<Map<String, String>> list = kingBdOrganizationMapper.getALLnot();
        if(list.size()>0){
            for(Map<String, String> map:list){
                if(map.containsKey("laber")){
                    redisCache.deleteObject("Cang"+map.get("laber"));
                }
            }
        }
    }

}
